home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1249 / coco.t < prev    next >
Text File  |  1997-04-18  |  897b  |  49 lines

  1. %
  2. % "coco.t" computes combinatorial coefficients
  3. %
  4. %   Sample program for the T Interpreter by:
  5. %
  6. %   Stephen R. Schmitt
  7. %   962 Depot Road
  8. %   Boxborough, MA 01719
  9. %
  10.  
  11. var i, selections, elements : int
  12. var answer : real
  13.  
  14. program
  15.  
  16.     prompt "Number of selections? "
  17.     get selections 
  18.     prompt "Out of how many elements? "
  19.     get elements 
  20.  
  21.     answer := elements
  22.     for i := 1 ... selections - 1 do
  23.  
  24.         elements := elements - 1
  25.         answer := answer * elements
  26.  
  27.     end for
  28.    
  29.     put "Nonunique combinations = ", answer
  30.     answer := answer / factorial( selections )
  31.     put "Unique combinations = ", answer
  32.  
  33. end program
  34.  
  35.  
  36. function factorial( n : int ) : real
  37.  
  38.     var result : real
  39.  
  40.     result := 1
  41.     loop
  42.         exit when n <= 0   
  43.         result := result * n
  44.         n := n - 1
  45.     end loop
  46.    
  47.     return result
  48.  
  49. end function